package com.smart.provider.controller;

import com.smart.provider.common.reqeust.UserRequestParams;
import com.smart.provider.common.response.ResponseVo;
import com.smart.provider.common.vo.UserVo;
import com.smart.provider.entity.User;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

/**
 * po ---> vo
 * entity  po对象  持久化对象
 * vo        返回客服端显示的对象
 */
@RestController
@Slf4j
@RequestMapping("/user")
public class UserController {
    @Value("${server.port}")
    private int port;

    @GetMapping("/pro")
    public ResponseVo<String> provider() {
        return ResponseVo.success("hello");
    }

    @GetMapping("/list")
    public ResponseVo<UserVo> users(int page, int size) {
        UserVo userVo = new UserVo();
        userVo.setUsername("admin");
        userVo.setUid(1);
        return ResponseVo.success(userVo);
    }

    /**
     * 客服端将对象转化成json数据直接上传
     * 维护
     *
     * @param requestParams
     * @return
     */
    @PostMapping("/register")
    public ResponseVo<UserVo> register(@RequestBody UserRequestParams requestParams) {
        UserVo userVo = new UserVo();
        userVo.setUid(2);
        userVo.setUsername("传递对象类型的数据");
        return ResponseVo.success(userVo);
    }

    /**
     * @return
     */
    @GetMapping("/detail/{uid}")
    public ResponseVo<UserVo> detail(@PathVariable Integer uid) {
        log.info("用户ID: {}", uid);
        UserVo userVo = new UserVo();
        userVo.setUid(3);
        userVo.setUsername("动态路径");
        return ResponseVo.success(userVo);
    }
    
    @GetMapping("/test")
    public ResponseVo<Integer> test() {
        return ResponseVo.success(port);
    }


}
